//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "DoubleStickyRatchetPayoff.h"
using namespace Cephei::QL::Instruments;
#include <gen/QL/Payoff.h>
using namespace Cephei::QL;
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Instruments::CDoubleStickyRatchetPayoff::CDoubleStickyRatchetPayoff (Double type1, Double type2, Double gearing1, Double gearing2, Double gearing3, Double spread1, Double spread2, Double spread3, Double initialValue1, Double initialValue2, Double accrualFactor) : CPayoff(CDoubleStickyRatchetPayoff::typeid)
{
    try
    {
#ifdef HANDLE
        _phDoubleStickyRatchetPayoff = NULL;
#endif
        QuantLib::Real _type1 = (QuantLib::Real)ValueHelper::Convert (type1);
        QuantLib::Real _type2 = (QuantLib::Real)ValueHelper::Convert (type2);
        QuantLib::Real _gearing1 = (QuantLib::Real)ValueHelper::Convert (gearing1);
        QuantLib::Real _gearing2 = (QuantLib::Real)ValueHelper::Convert (gearing2);
        QuantLib::Real _gearing3 = (QuantLib::Real)ValueHelper::Convert (gearing3);
        QuantLib::Real _spread1 = (QuantLib::Real)ValueHelper::Convert (spread1);
        QuantLib::Real _spread2 = (QuantLib::Real)ValueHelper::Convert (spread2);
        QuantLib::Real _spread3 = (QuantLib::Real)ValueHelper::Convert (spread3);
        QuantLib::Real _initialValue1 = (QuantLib::Real)ValueHelper::Convert (initialValue1);
        QuantLib::Real _initialValue2 = (QuantLib::Real)ValueHelper::Convert (initialValue2);
        QuantLib::Real _accrualFactor = (QuantLib::Real)ValueHelper::Convert (accrualFactor);
        _ppDoubleStickyRatchetPayoff = new boost::shared_ptr<QuantLib::DoubleStickyRatchetPayoff> (new QuantLib::DoubleStickyRatchetPayoff ( _type1,  _type2,  _gearing1,  _gearing2,  _gearing3,  _spread1,  _spread2,  _spread3,  _initialValue1,  _initialValue2,  _accrualFactor ));
        SetPayoff (boost::dynamic_pointer_cast<QuantLib::Payoff> (*_ppDoubleStickyRatchetPayoff));
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Instruments::CDoubleStickyRatchetPayoff::CDoubleStickyRatchetPayoff (boost::shared_ptr<QuantLib::DoubleStickyRatchetPayoff>& childNative, Object^ owner) : CPayoff(CDoubleStickyRatchetPayoff::typeid)
{
#ifdef HANDLE
	_phDoubleStickyRatchetPayoff = NULL;
#endif
	_ppDoubleStickyRatchetPayoff = &childNative;
    _ppPayoff = new boost::shared_ptr<QuantLib::Payoff> (boost::dynamic_pointer_cast<QuantLib::Payoff> (*_ppDoubleStickyRatchetPayoff));
}
Cephei::QL::Instruments::CDoubleStickyRatchetPayoff::CDoubleStickyRatchetPayoff (QuantLib::DoubleStickyRatchetPayoff& childNative, Object^ owner) : CPayoff(CDoubleStickyRatchetPayoff::typeid)
{
#ifdef HANDLE
	_phDoubleStickyRatchetPayoff = NULL;
#endif
	_ppDoubleStickyRatchetPayoff = new boost::shared_ptr<QuantLib::DoubleStickyRatchetPayoff> (&childNative);
    _ppPayoff = new boost::shared_ptr<QuantLib::Payoff> (boost::dynamic_pointer_cast<QuantLib::Payoff> (*_ppDoubleStickyRatchetPayoff));
    _DoubleStickyRatchetPayoffOwner = owner;
    _PayoffOwner = owner;
}

Cephei::QL::Instruments::CDoubleStickyRatchetPayoff::CDoubleStickyRatchetPayoff (CDoubleStickyRatchetPayoff^ copy) : CPayoff(CDoubleStickyRatchetPayoff::typeid)
{
#ifdef HANDLE
	_phDoubleStickyRatchetPayoff = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppDoubleStickyRatchetPayoff = new boost::shared_ptr<QuantLib::DoubleStickyRatchetPayoff> (copy->GetShared());
        _ppPayoff = new boost::shared_ptr<QuantLib::Payoff> (boost::dynamic_pointer_cast<QuantLib::Payoff> (*_ppDoubleStickyRatchetPayoff));
    }
}
Cephei::QL::Instruments::CDoubleStickyRatchetPayoff::CDoubleStickyRatchetPayoff (System::Type^ t) : CPayoff(CDoubleStickyRatchetPayoff::typeid)
{
#ifdef HANDLE
	_phDoubleStickyRatchetPayoff = NULL;
#endif
	if (!t->IsSubclassOf(CDoubleStickyRatchetPayoff::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Instruments::CDoubleStickyRatchetPayoff::CDoubleStickyRatchetPayoff (QuantLib::Handle<QuantLib::DoubleStickyRatchetPayoff>& childNative, Object^ owner)  : CPayoff(CDoubleStickyRatchetPayoff::typeid)
{
	_phDoubleStickyRatchetPayoff = &childNative;
	_ppDoubleStickyRatchetPayoff = &static_cast<boost::shared_ptr<QuantLib::DoubleStickyRatchetPayoff>>(childNative.currentLink());
    _ppPayoff = new boost::shared_ptr<QuantLib::Payoff> (boost::dynamic_pointer_cast<QuantLib::Payoff> (*_ppDoubleStickyRatchetPayoff));
    _DoubleStickyRatchetPayoffOwner = owner;
}
Cephei::QL::Instruments::CDoubleStickyRatchetPayoff::CDoubleStickyRatchetPayoff (QuantLib::Handle<QuantLib::DoubleStickyRatchetPayoff> childNative)  : CPayoff(CDoubleStickyRatchetPayoff::typeid)
{
	_phDoubleStickyRatchetPayoff = &childNative;
	_ppDoubleStickyRatchetPayoff = &static_cast<boost::shared_ptr<QuantLib::DoubleStickyRatchetPayoff>>(childNative.currentLink());
    _ppPayoff = new boost::shared_ptr<QuantLib::Payoff> (boost::dynamic_pointer_cast<QuantLib::Payoff> (*_ppDoubleStickyRatchetPayoff));
}
#endif
#ifdef STRUCT
Cephei::QL::Instruments::CDoubleStickyRatchetPayoff::CDoubleStickyRatchetPayoff (QuantLib::DoubleStickyRatchetPayoff childNative)  : CPayoff(CDoubleStickyRatchetPayoff::typeid)
{
#ifdef HANDLE
	_phDoubleStickyRatchetPayoff = NULL;
#endif
	_ppDoubleStickyRatchetPayoff = new boost::shared_ptr<QuantLib::DoubleStickyRatchetPayoff> (new QuantLib::DoubleStickyRatchetPayoff (childNative));
    _ppPayoff = new boost::shared_ptr<QuantLib::Payoff> (boost::dynamic_pointer_cast<QuantLib::Payoff> (*_ppDoubleStickyRatchetPayoff));
}
#endif

Cephei::QL::Instruments::CDoubleStickyRatchetPayoff::~CDoubleStickyRatchetPayoff ()
{
    if (_ppDoubleStickyRatchetPayoff != NULL)
    {
	    delete _ppDoubleStickyRatchetPayoff;
        _ppDoubleStickyRatchetPayoff = NULL;
    }
}
Cephei::QL::Instruments::CDoubleStickyRatchetPayoff::!CDoubleStickyRatchetPayoff ()
{
    if (_ppDoubleStickyRatchetPayoff != NULL)
    {
	    delete _ppDoubleStickyRatchetPayoff;
    }
}
QuantLib::DoubleStickyRatchetPayoff& Cephei::QL::Instruments::CDoubleStickyRatchetPayoff::GetReference ()
{
    if (_ppDoubleStickyRatchetPayoff == NULL) throw gcnew NativeNullException ();
	return **_ppDoubleStickyRatchetPayoff;
}
boost::shared_ptr<QuantLib::DoubleStickyRatchetPayoff>& Cephei::QL::Instruments::CDoubleStickyRatchetPayoff::GetShared ()
{
    if (_ppDoubleStickyRatchetPayoff == NULL) throw gcnew NativeNullException ();
	return *_ppDoubleStickyRatchetPayoff;
}
QuantLib::DoubleStickyRatchetPayoff* Cephei::QL::Instruments::CDoubleStickyRatchetPayoff::GetPointer ()
{
    if (_ppDoubleStickyRatchetPayoff == NULL) throw gcnew NativeNullException ();
	return &**_ppDoubleStickyRatchetPayoff;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::DoubleStickyRatchetPayoff>& Cephei::QL::Instruments::CDoubleStickyRatchetPayoff::GetHandle ()
{
	if (_phDoubleStickyRatchetPayoff == NULL)
	{
		_phDoubleStickyRatchetPayoff = new Handle<QuantLib::DoubleStickyRatchetPayoff> (*_ppDoubleStickyRatchetPayoff);
	}
	return *_phDoubleStickyRatchetPayoff;
}
#endif
bool Cephei::QL::Instruments::CDoubleStickyRatchetPayoff::HasNative () 
{
	return (_ppDoubleStickyRatchetPayoff != NULL);
}

String^ Cephei::QL::Instruments::CDoubleStickyRatchetPayoff::Description::get ()
{
    try
    {
    	std::string _rv = (std::string)(*_ppDoubleStickyRatchetPayoff)->description ( );   
        String^ _nrv = (String^)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
String^ Cephei::QL::Instruments::CDoubleStickyRatchetPayoff::Name::get ()
{
    try
    {
    	std::string _rv = (std::string)(*_ppDoubleStickyRatchetPayoff)->name ( );   
        String^ _nrv = (String^)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Instruments::IDoubleStickyRatchetPayoff^ Cephei::QL::Instruments::CDoubleStickyRatchetPayoff_Factory::Create (Double type1, Double type2, Double gearing1, Double gearing2, Double gearing3, Double spread1, Double spread2, Double spread3, Double initialValue1, Double initialValue2, Double accrualFactor)
{
    return gcnew CDoubleStickyRatchetPayoff ( type1,  type2,  gearing1,  gearing2,  gearing3,  spread1,  spread2,  spread3,  initialValue1,  initialValue2,  accrualFactor);
}
